
  class ListNode {
      int val;
      ListNode next;
      ListNode(int x) {
          val = x;
          next = null;
      }
  }

public class Solution {
    public int size(ListNode head){
        ListNode node=head;
        int count=0;
        while(node!=null){
            node=node.next;
            count++;
        }
        return count;
    }
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        
        ListNode nodeA=headA;
        ListNode nodeB=headB;
        int lenA=size(headA);
        int lenB=size(headB);
        ListNode fast=headA;
        ListNode slow=headB;
        int len=lenA-lenB;
        if(len<0){
            len=lenB-lenA;
            fast=headB;
            slow=headA;
        }
        while(len>0){
            fast=fast.next;
            len--;
        }
        while(fast!=slow&&fast!=null){
            fast=fast.next;
            slow=slow.next;
        }
        
        return fast;
       
    }
}